
const {get} = require('../../utils/http')

Page({
  data: {
    longitude:'113.324520',
    latitude:'23.099994',
    markers:[]
  },
  onLoad(){
    this.getLocation();
  },
  onReady(){
    this.mapContext = wx.createMapContext('map');
    this.getMarkers();
  },
  getLocation(){
    wx.getLocation({
      type: 'wgs84',
      success: (res)=> {
        this.setData({
          longitude:res.longitude,
          latitude:res.latitude
        })
        console.log(res);
      }
     })
  },
  async getMarkers(){
   let result = await get('/index.php/trade/get_list');
   let list=[];
    result.data.forEach((item,index)=>{
      let params ={
        ...item,
        iconPath:item.type ==="sell"? "/images/sell.png":"/images/buy.png"
      }
      list.push(params);
   });
   console.log(list)
   this.setData({
     markers:list
   })
  },
  movetocenter(){
    this.mapContext.moveToLocation()
  },
  goPublish(){
    wx.navigateTo({
      url: '/pages/publish/publish',
    })
  }
})
